<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>第四章 事件测试</title>
    </head>
    <body>
        <a id="test1" style="cursor:hand;" href="http://www.sina.com.cn" onclick="alert('direct:'+id);alert(e.clinntX);">
        test1,click me!
        </div>
        <script type="text/javascript">
            window.onload = function(){
                var n = document.getElementById('test1');
                n.onclick = function(e){
                    alert('attribute:' + this.id);
                    return false;
                }
                
                function addEvent(elem, type, fn){
                    if (elem.addEventListener)// FF
                        elem.addEventListener(type, fn, false);
                    else 
                        if (elem.attachEvent)// IE
                            elem.attachEvent("on" + type, fn);
                }
                
                function clickme1(e){
                    alert('normal1:' + this.id);
                }
                
                addEvent(n, 'click', clickme1);
                
                function clickme2(e){
                    e = e || window.event;
                    alert('normal2:' + this.id);
                    if (e.preventDefault) 
                        e.preventDefault();
                    else 
                        e.returnValue = false;
                }
                
                addEvent(n, 'click', clickme2);
            }
        </script>
    </body>
</html>
